#include "stdafx.h"
#include "ckConstraint.h"
#include "ckValue.h"

namespace ck
{
	Constraint::Constraint()
	{
		m_pValue = NULL;
		m_op = ckCmpOpEqualTo;
	}


	Constraint::~Constraint()
	{
		if (m_pValue)
		{
			m_pValue->Release();
			m_pValue = NULL;
		}
		Cleanup();
	}

	RESULTCODE Constraint::SetKey(const char* szKey)
	{
		if (szKey == NULL)
		{
			return RC_FAILURE;
		}
		m_strKey = szKey;

		return RC_SUCCESS;
	}

	const char*	Constraint::GetKey()
	{
		return m_strKey.c_str();
	}

	Value* Constraint::GetValue()
	{
		return m_pValue;
	}

	RESULTCODE Constraint::SetValue(Value* pValue)
	{
		if (m_pValue)
		{
			m_pValue->Release();
			m_pValue = NULL;
		}
		m_pValue = pValue;
		return RC_SUCCESS;
	}

	z_uint32 Constraint::GetComparision()
	{
		return m_op;
	}

	void Constraint::SetComparision(ckCmpOp op)
	{
		m_op;
	}

	void Constraint::Cleanup()
	{
		std::vector<Value*>::iterator iter;
		for (iter = m_values.begin(); iter != m_values.end(); iter++)
		{
			(*iter)->Release();
		}
		m_values.clear();
	}

	z_uint32 Constraint::GetValueCount()
	{
		return m_values.size();
	}

	Value* Constraint::GetValue(z_uint32 i)
	{
		if (i >= m_values.size())
		{
			return NULL;
		}
		return m_values[i];
	}

	RESULTCODE Constraint::AddValue(Value* pValue)
	{
		if(pValue==NULL)
		{
			return RC_FAILURE;
		}
		m_values.push_back(pValue);
		return RC_SUCCESS;
	}

	const char* Constraint::GetDescription()
	{
		return m_strDescription.c_str();
	}

	void Constraint::SetDescription(const char* szDescription)
	{
		if (szDescription == NULL)
		{
			m_strDescription.clear();
		}
		m_strDescription = szDescription;
	}

}